package com.ruoyi.business.controller;

import com.ruoyi.business.domain.query.AccountBookQuery;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.domain.group.Add;
import com.ruoyi.common.core.domain.group.Update;
import com.ruoyi.business.domain.form.AccountBookForm;
import com.ruoyi.business.service.AccountBookService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 账本接口
 */
@Validated
@RequiredArgsConstructor
@Tag(name = "账本接口")
@RestController
@RequestMapping("/business/book")
public class AccountBookController extends BaseController {

    private final AccountBookService accountBookService;

    @PostMapping
    @Operation(summary = "添加")
    public Result add(@RequestBody @Validated(Add.class) AccountBookForm form){
        return accountBookService.add(form);
    }

    @PutMapping
    @Operation(summary = "修改")
    public Result update(@RequestBody @Validated(Update.class)AccountBookForm form){
        return accountBookService.update(form);
    }

    @DeleteMapping("/{ids}")
    @Operation(summary = "批量删除")
    public Result remove(@PathVariable("ids") @NotEmpty(message = "请选择数据")List<String> ids){
        return accountBookService.remove(ids);
    }

    @GetMapping("/page")
    @Operation(summary = "分页")
    public Result page(AccountBookQuery query){
        return accountBookService.page(query);
    }

    @GetMapping("/{id}")
    @Operation(summary = "详情")
    public Result detail(@PathVariable("id")String id){
        return accountBookService.detail(id);
    }

    @GetMapping("/list")
    @Operation(summary = "列表")
    public Result list(AccountBookQuery query){
        return accountBookService.list(query);
    }

}
